define(function (require) {
    var _common = require('common/main');
    var _config = require('common/config');
    var _send = _common.sendRequest;
    function init() {
    	$('#new_food_confirm').click(_save_food_place);
    }
    
    
    function _save_food_place()
    {
    	//get from session or cookie
    	var _userid = 0;
    	var _name = $('#food_name').val();
    	var _type = $('#food_type').val();
    	var _desc = $('#food_desc').val();
//    	var _imagepath = $('#food-image-show').attr('src');
    	var _image = $('#food_imagebase').val();
    	var _imagepc = $('#food_imagebase_pc').val();
    	var _flag1 = $('#food_flag1').val();
    	var _flag2 = $('#food_flag2').val();
    	var _flag3 = $('#food_flag3').val();
    	var _flag4 = $('#food_flag4').val();
    	var _flag5 = $('#food_flag5').val();
    	var _protein = $('#food_protein').val();
    	var _carbo = $('#food_carbo').val();
    	var _fat = $('#food_fat').val();
    	var _vitamin = $('#food_vitamin').val();
    	var _calorie = $('#food_calorie').val();
    	var _value = $('#food_value').val();
    	var _df = $('#food_df').val();
    	var _mineral = $('#food_mineral').val();
    	var _state = $('#food_state option:selected').attr("value");
    	var _price = $('#food_price').val();
    	var _param = _common.stringify({
			userid : _userid,
			name : _name,
			type : _type,
			desc : _desc,
			image : _image,
			imagepc : _imagepc,
			flag1 : _flag1,
			flag2 : _flag2,
			flag3 : _flag3,
			flag4 : _flag4,
			flag5 : _flag5,
			protein : _protein,
			carbo : _carbo,
			fat : _fat,
			vitamin : _vitamin,
			calorie : _calorie,
			value : _value,
			df : _df,
			mineral : _mineral,
			state : _state,
			price : _price
		});
    	_send("saveFood.ajax",_param,_save_render);
    }
    
    function _save_render(data)
    {
    	if(data)
		{
    		alert("新增成功");
    		window.close();
		}
    	else
		{
    		alert("新增失败，请修改后重新提交");
		}
    }
    
    
    return { init: init };
});